<%--
  Created by IntelliJ IDEA.
  User: hejx
  Date: 2017/5/19
  Time: 15:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--头部-->
    <jsp:include page="/template/header.jsp" />
    <!--头部结束-->
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>添加用户</title>
    <link rel="shortcut icon" href="<%=basePath%>static/favicon.ico">
    <link href="<%=basePath%>static/css/plugins/iCheck/custom.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div ng-app="myApp" ng-controller="addUserController" class="wrapper wrapper-content scroll-wrapper">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">姓名<span style="color: red;">*</span></label>
                                <div class="col-sm-8">
                                    <input  ng-model="user.realname" type="text" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">电话<span style="color: red;">*</span></label>
                                <div class="col-sm-8">
                                    <input  ng-model="user.phone" maxlength="11" type="text" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">邮箱</label>
                                <div class="col-sm-8">
                                    <input  ng-model="user.email" type="text" class="form-control">
                                </div>
                            </div>
                            <div ng-show="showPwd" class="hr-line-dashed"></div>
                            <div ng-show="showPwd" class="form-group">
                                <label class="col-sm-2 control-label">密码</label>
                                <div class="col-sm-8">
                                    <input type="text" value="123456" readonly class="form-control"> <span class="help-block m-b-none" style="color: red;">初始密码为123456,请该用户自己登录后进行修改</span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户职位
                                </label>
                                <div class="col-sm-8">
                                    <select ng-model="user.roleId" class="form-control m-b" name="roleId">
                                        <option value="-1">请选择职位</option>
                                        <c:forEach var="role" items="${roles}">
                                            <option value="${role.pkId}">${role.roleName}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" ng-click="addUser()" id="subBtn" type="button">保存内容</button>
                                    <button class="btn btn-white" onclick="parent.closeWin()" type="button">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 导入尾部公共js -->
    <jsp:include page="/template/tail.jsp" />


<script>
    $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});

    app.controller('addUserController', function($scope,$http) {

        $scope.user;
        $scope.url;
        $scope.showPwd = true;

        if('${update}'=='6'){
            $scope.user = angular.fromJson('${user}');
            $scope.url = "/admin/user/update";
            $scope.showPwd = false;
        }else{
            $scope.user = {
                realname:'',
                phone:'',
                email:'',
                roleId:-1,
                pwd:'123456'    //默认密码123456 不可修改 这里的密码后台没有使用
            };
            $scope.url = "/admin/user/add";
        }

        //新增用户
        $scope.addUser = function(){

            if(!validatemobile($scope.user.phone)){
                layer.msg(common.ERR_MSG.PHONE_ERROR_MSG);
                return false;
            }
            if(!isNull($scope.user.email)){
                if(!validateEmail($scope.user.email)){
                    layer.msg(common.ERR_MSG.EMAIL_ERROR_MSG);
                    return false;
                }
            }
            if($scope.user.roleId==-1){
                layer.msg("请选择用户职位");
                return false;
            }

            $('#subBtn')[0].disabled = true;

            //提交数据
            $http({method : 'POST', data:$scope.user, url : $scope.url})
                .success(function(data,status,headers,config){
                    console.log(data);
                    $('#subBtn')[0].disabled = false;
                    if(data.code==0){
                        alert("成功");
                        parent.closeWinAndFlush();
                    }else{
                        layer.msg(data.msg);
                    }
                }).error(function(data,status,headers,config){
                $('#subBtn')[0].disabled = false;
                console.log('error..........');
                console.log(data);
            });
        }


    });

</script>
</body>


<!-- Mirrored from www.zi-han.net/theme/hplus/form_basic.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:19:15 GMT -->
</html>